#!/bin/bash
###
 # @Author: didiplus
 # @Description: 
 # @Date: 2025-08-07 14:10:17
 # @LastEditors: didiplus
 # @LastEditTime: 2025-08-08 14:35:32
 # @FilePath: /script/StarInspect/playbook/merge_jsons.sh
 # @Version: 1.0
### 

# 获取当前日期，格式为 YYYY-MM-DD
DATE=$(date +"%Y-%m-%d")
#使用日期作为后缀生成文件名
OUTPUT_FILE="./data/hosts_${DATE}.json"
# 先清空文件内容
true > "${OUTPUT_FILE}"
echo "[" > "${OUTPUT_FILE}"
for file in output/*.json; do
  cat "$file" >> "${OUTPUT_FILE}"
  echo "," >> "${OUTPUT_FILE}"
done
sed -i '$ s/,$//' "${OUTPUT_FILE}"
echo "]" >> "${OUTPUT_FILE}"
echo "✅ 已生成统一 ${OUTPUT_FILE}"